package openadmin.model.territory;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint; 

import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;

import openadmin.dao.Base;

@Entity
@Table(name = "coordinate", schema = "territory", uniqueConstraints = @UniqueConstraint(columnNames =  "description"))
public class Coordinate implements Base, java.io.Serializable{

	/** attribute that contains the identifier*/
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)	
	private Integer id;

	/** attribute that contains the latitude*/	
	@NotNull
	private Double latitude;
	
	/** attribute that contains the longitude*/	
	@NotNull
	private Double longitude;
				
	/** attribute that contains the description (reference catastral), unique value*/
	@Length(max = 14)
	@NotNull
	private String description;
	
	/** attribute that contains the post code */
	private Integer postcode;
	
	/** Transient attribute that means that the system should make a log on any JPA operation of this class*/
	@Transient
	private boolean debuglog = true;
	
	/** Transient attribute that means that the system should make a historic on any JPA operation of this class*/
	@Transient
	boolean historiclog = false;
	
	/** attribute that contains the relationship with Address*/
	//@OneToMany(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER, mappedBy = "coordinate")
	//private Set<Address> address = new HashSet<Address>(0);		

	/**
	 * Constructor of the class Coordinate.
	 * without parameters
	 */
	public Coordinate() {
		
	}
	
	/** Getters and setters*/
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Double getLatitude() {
		return latitude;
	}

	public void setLatitude(Double latitude) {
		this.latitude = latitude;
	}

	public Double getLongitude() {
		return longitude;
	}

	public void setLongitude(Double longitude) {
		this.longitude = longitude;
	}

	public String getDescription() {
		return description.toUpperCase();
	}

	public void setDescription() {
		this.description = latitude.toString() + " " + longitude.toString();
	}

	public Integer getPostcode() {
		return postcode;
	}

	public void setPostcode(Integer postcode) {
		this.postcode = postcode;
	}
	
	public boolean getDebugLog() {
		
		return debuglog;
	}
	
	public void setDebugLog(boolean pDebuglog) {
		
		debuglog = pDebuglog;
	
	}
	
	public boolean getHistoricLog() {
		return historiclog;
	}

	public void setHistoricLog(boolean historiclog) {
		this.historiclog = historiclog;
	}

	@Override
	public String toString(){
		 
		 return description;
	}
	
}
